package com.da.javatest.leetCode2;

import java.util.Collections;

public class Code559 {
    public static void main(String[] args) {
        Node node = new Node(1, Collections.singletonList(new Node(2, Collections.singletonList(new Node(3, null)))));
        new Code559().maxDepth(node);
    }


    private int max = 0;

    public int maxDepth(Node root) {
        getMax(root, 0);
        return max;
    }

    private int getMax(Node root, int deep) {
        if (root == null) return deep;
        deep++;
        if (root.children != null) {
            for (Node child : root.children) {
                getMax(child, deep);
            }
        }
        max = deep > max ? deep : max;
        return deep;
    }
}
